home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / c / cdk_vb.exe / CDK_BC.TXT < prev   
Text File  |  1991-09-01  |  25KB  |  627 lines

  1.  
  2.  
  3.  
  4.                              Using Borland C++ IDE with 
  5.                the Microsoft Visual BASIC Control Development Kit (CDK)
  6.  
  7.  
  8.  
  9.           I wrote this description to help anyone using Borland's C++
  10.           compiler and Integrated Development Environment (IDE) to create
  11.           custom controls for use with Microsoft's Visual BASIC.  The MS
  12.           CDK (Control Development Kit) has a series of example programs
  13.           that were written to work with Microsoft C version 6 or later. 
  14.           This document should help you get them to work using Borland's
  15.           development products.
  16.  
  17.           This document assumes that you have purchased the MS CDK product. 
  18.           I make reference to specific line numbers within the files that
  19.           were shipped to me with version 1.0 of that product.  When
  20.           working with Borland's IDE, you can tell what line that you are
  21.           currently editing by referencing the numbers in the bottom left-
  22.           hand corner of the active edit window.  The numbers shown there
  23.           appear in the format:
  24.  
  25.                           <line number> : <column position>
  26.  
  27.           for example:
  28.                                         25:32
  29.  
  30.           which says that your cursor is on the 32nd character of line 25.
  31.  
  32.           In this document, I also assume that you have installed your
  33.           Borland C++ product in the drive\subdirectory C:\BORLANDC.  Also
  34.           that after installing the CDK, you have copied the file VBAPI.LIB
  35.           to C:\BORLANDC\LIB and the file VBAPI.H to C:\BORLANDC\INCLUDE.
  36.  
  37.           While experimenting with this code, I created a subdirectory
  38.           called TEMP under the directory for each control, copied all
  39.           files for that control there, and edited the copies.  It is NEVER
  40.           advisable to edit your original copies of anything.  Also
  41.           remember that whenever you are coding at a systems-level, you
  42.           should save your code frequently.
  43.  
  44.           If you have any comments, suggestions, or neat VBX files, please
  45.           feel free to drop me a line in my Compuserve mailbox, or at my
  46.           humble homestead at 1188 Morgan Ave, Williamsport, PA 17701.
  47.  
  48.           Throughout this document, I mention products and programs that
  49.           are protected by some sort of legal nonsense or another, and I
  50.           hope I can appease all legal-eagles by saying that any Borland
  51.           product mentioned is trademarked and legally protected by Borland
  52.           International Inc. of Scotts Valley, CA.  Any Microsoft product
  53.           is trademarked and legally protected by Microsoft Corporation of
  54.           Redmond, WA.  Anything done by you using the descriptions here
  55.           should make neither them (nor me) liable for any silliness that
  56.           might prevail.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.           Brent K. Langley  Compuserve Userid 70312,2142             Page 1
  66.  
  67.  
  68.                              Using Borland C++ IDE with 
  69.                the Microsoft Visual BASIC Control Development Kit (CDK)
  70.  
  71.  
  72.  
  73.           GETTING THE CDK TO WORK:
  74.  
  75.           I have found that in getting the CDK code to work with the IDE
  76.           there are 8 steps that I had to follow:
  77.  
  78.           1)   Change WINDOWS.H
  79.           2)   Copy and Rename LibInit.Obj to C:\BORLANDC\LIB\C0VBINIT.OBJ 
  80.           3)   Create a Project file (.PRJ) to create the VBX/DLL file
  81.           4)   Change CCINIT.C to take advantage of changes in WINDOWS.H
  82.           5)   Handle any syntax errors in demo code
  83.           6)   Handle any language incompatibilities in code
  84.           7)   "Make" Project from IDE
  85.           8)   Rename (or Copy) xxxxxxxx.DLL to xxxxxxxx.VBX
  86.  
  87.           Steps 1 and 2 from above only need to be done once.  Steps 3 and
  88.           4 need to be done for every project, but follow the same steps. 
  89.           Steps 5 and 6 will be addressed separatly for each of the three
  90.           example programs that need fixing.  Steps 7 and 8 let you put all
  91.           of the pieces together. 
  92.  
  93.           STEP ONE:  CHANGE WINDOWS.H
  94.  
  95.           The normal startup code for a DLL does a little processing and
  96.           then calls your function called LibMain.  In a .VBX file, we have
  97.           to replace the normal startup code with a modified routine that
  98.           passes some extra information to our control's LibMain.  This
  99.           means that the format for calling a VBX's LibMain is different
  100.           from a normal DLL's LibMain.  This causes no real hassle to
  101.           MSC/SDK developers because Microsoft doesn't include a function
  102.           prototype in their version of WINDOWS.H for LibMain, however,
  103.           Borland does.  And when Borland's compiler sees the CDK version
  104.           of the LibMain function, it stops compiling with an error.
  105.  
  106.           We could just remove the function prototype for LibMain from
  107.           Borland's WINDOWS.H, but it will help us with our syntax checking
  108.           if we leave it there.  My solution is to define a constant called
  109.           _CDK before the #include of WINDOWS.H.  Then have WINDOWS.H
  110.           determine the existance of this defined constant to decide
  111.           whether to use the CDK or normal version of LibMain.
  112.  
  113.           To do this, load C:\BORLANDC\INCLUDE\WINDOWS.H and then press
  114.           Ctrl-PgDn to go to the bottom of the file.  Move your cursor up
  115.           to about line 3473, and you should see Borland's function
  116.           prototype for LibMain.  I changed this part of the code to be:
  117.  
  118.           #ifndef  _CDK
  119.           int FAR PASCAL LibMain ( HANDLE, WORD, WORD, LPSTR );
  120.           #else
  121.           BOOL FAR PASCAL LibMain( HANDLE, HANDLE, unsigned short );
  122.           #endif
  123.  
  124.           I used "unsigned short" instead of USHORT for the third parameter
  125.           of the CDK version of LibMain because USHORT isn't seen in a
  126.           typedef statement until the file VBAPI.H is #include'd later.
  127.  
  128.  
  129.           Brent K. Langley  Compuserve Userid 70312,2142             Page 2
  130.  
  131.  
  132.                              Using Borland C++ IDE with 
  133.                the Microsoft Visual BASIC Control Development Kit (CDK)
  134.  
  135.  
  136.  
  137.           STEP TWO:  RENAME LIBINIT.OBJ TO C0VBINIT.OBJ
  138.  
  139.           Page 20 of the CDK Guide explains that LIBINIT.OBJ contains
  140.           initialization code to replace the code from the file
  141.           LIBENTRY.OBJ that is normally linked into DLL projects first.  So
  142.           we must ensure that the code from LIBINIT.OBJ is linked before
  143.           any other code in our projects.
  144.  
  145.           On page 141 of Borland's C++ User Guide, we find the section of
  146.           the project manager chapter titled "Overriding Libraries" states
  147.           that we can have our own startup file linked first, if:
  148.  
  149.                1)   its name starts with C0 (the letter C followed by zero)
  150.                2)   it is placed as the first file in the project.
  151.  
  152.           We'll worry about making a project file in a minute, but for now,
  153.           lets give LibInit.OBJ a new name to conform with step one from
  154.           above.  While we're at it, lets also move it to a standard
  155.           location (since the CDK manual says that this code would seldom
  156.           need to change.)  If LibInit.OBJ is in your current directory,
  157.           type:
  158.  
  159.                     COPY LIBINIT.OBJ  C:\BORLANDC\LIB\C0VBINIT.OBJ
  160.  
  161.           You could call it anything you want (so long as it starts with
  162.           "C0") but since it contains the Visual Basic INITialization code,
  163.           I thought that this name was appropriate.
  164.  
  165.           STEP THREE:  CREATE A PROJECT FILE
  166.  
  167.           For each control, you will make a project file that looks similar
  168.           to the following:
  169.  
  170.                               C:\BORLANDC\LIB\C0VBINIT.OBJ
  171.                               C:\BORLANDC\LIB\C0DC.OBJ
  172.                               C:\BORLANDC\LIB\VBAPI.LIB
  173.                               CCINIT.C
  174.                               program.DEF
  175.                               program.RC
  176.                               program.C
  177.